/* apply style changes to a specific element */

function applyFont(element, font) {  
  if (document.getElementById(element)) {
    document.getElementById(element).style.fontFamily = font;
  }
}

function applyFontSize(element, size) {  
  if (document.getElementById(element)) {
    document.getElementById(element).style.fontSize = size;
  }
}

function applyFontStyle(element, style) {
  if (document.getElementById(element)) {

	switch (style) {
	  case 'normal':
		document.getElementById(element).style.fontStyle = 'normal';
		document.getElementById(element).style.fontWeight = 'normal';
		break;
	  case 'bold':
		document.getElementById(element).style.fontStyle = 'normal';
		document.getElementById(element).style.fontWeight = 'bold';
		break;
	  case 'italic':
		document.getElementById(element).style.fontStyle = 'italic';
		document.getElementById(element).style.fontWeight = 'normal';
		break;
	  case 'bold italic':
		document.getElementById(element).style.fontStyle = 'italic';
		document.getElementById(element).style.fontWeight = 'bold';
		break;
	  default:
	    document.getElementById(element).style.fontStyle = 'inherit';
		document.getElementById(element).style.fontWeight = 'inherit';
		break;	
	}
	
  }
}

function applyFontColor(element, color) { 
  var reg = new RegExp('[^a-fA-F0-9]', 'g');
  color = color.replace(reg, '');
 
  if (color == null || color.length < 3) {
    color = '#ffffff';
  } else if (color.length >= 3 && color.length < 6) {
    color = '#' + color.substr(0,3);
  } else if (color.length >= 6) {
    color = '#' + color.substr(0,6);
  }
  
  if (color.length == 4 || color.length == 7) {
    if (document.getElementById(element)) {
	  document.getElementById(element).style.color = color;
    }
  }
}